package module.shop.view
{
	import com.darwin.darwinUI.controls.Label;
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	import com.greensock.easing.Circ;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	import module.main.event.MainEvent;

	public class ResouseAnimation extends Sprite
	{
		private var _x:Number;
		private var _y:Number;	
		private var _resouseLabel:Label;
		private var _type:String
		private var _resouseNum:int
		/**
		 *飘收获动画类 			
		 * @param item			动画对象
		 * @param resouseNum	资源数量
		 * @param x				动画播放位置x坐标
		 * @param y				动画播放位置y坐标
		 * @param type			资源名称
		 * 
		 */		
		public function ResouseAnimation(item:Sprite,resouseNum:int,x:Number,y:Number,type:String)
		{
			_resouseLabel = new Label();
			_resouseLabel.text = "+" + resouseNum.toString();
			_resouseLabel.x = item.width + 5;
			_type = type;
			_resouseNum = resouseNum;
			
			this.addChild(item);
			this.addChild(_resouseLabel);
			this.addEventListener(Event.ADDED_TO_STAGE,start);
			this.x = x;
			this.y = y;
			_x = x;
			_y = y;
		}
		private function start(e:Event):void
		{
			TweenMax.to(this, 0.8, {bezier:[{x:_x, y:_y - 100}], alpha:0, ease:Circ.easeIn,onComplete:completeHandler});
		}
		private function completeHandler():void
		{
			var gainResouceEvent:MainEvent = new MainEvent(MainEvent.GAIN_RESOUSE_EVENT);
			var resource:Object = new Object;
			resource.num = _resouseNum;
			resource.type = _type;
			gainResouceEvent.data = resource;
			this.dispatchEvent(gainResouceEvent);
			/*if(this.parent)
			{
				this.parent.removeChild(this);
			}*/
		}
	}
}